import { createApp } from 'vue';
import { router, formatRouters } from './router';

import ElementPlus from 'element-plus';
import '@/styles/index.scss';

import axios from 'axios';
import { initAxios } from './axios.interceptor';
initAxios(axios);

import { store } from './store';
import { userStore, menuStore } from '@/store/modules';

import App from './app.vue';
import { hasLogin } from './utils/auth';
import { getItem, USER_INFO } from './utils/db';

(async () => {
  await userStore.getTenant();
  await Promise.all([menuStore.getPageMenu(), menuStore.getUserMenu(), menuStore.getOtherMenu(), menuStore.getCompanyInfo()]);
  const { allMenu } = menuStore;
  formatRouters(allMenu, router);

  if (hasLogin()) {
    userStore.setUserInfo(getItem(USER_INFO));
  }

  createApp(App)
    .use(ElementPlus)
    .use(store)
    .use(router)
    .mount('#app');
})();
